using System;
using System.Configuration;

namespace NHConfiguration
{
    public enum NhTypeApplication
    {
        Web,
        WebService,
        Test
    }

    public sealed class NhibernateConfigurationSection : ConfigurationSection
    {
        private static ConfigurationPropertyCollection _properties;

        private static readonly ConfigurationProperty _strHibernateFile = new ConfigurationProperty("HibernateFile",typeof (string),"hibernate.cfg.xml",ConfigurationPropertyOptions.IsRequired);
        private static readonly ConfigurationProperty _strMappingPath = new ConfigurationProperty("MappingPath",typeof (string), "",ConfigurationPropertyOptions.IsRequired);
        private static readonly ConfigurationProperty _strNhTypeApplication = new ConfigurationProperty("NhTypeApplication", typeof(NhTypeApplication), NhTypeApplication.Web, ConfigurationPropertyOptions.IsRequired);
        
        public NhibernateConfigurationSection()
        {
            _properties = new ConfigurationPropertyCollection {_strHibernateFile, _strMappingPath,_strNhTypeApplication };
        }

        public static NhibernateConfigurationSection CurrentConfiguration
        {
            get
            {
                return (NhibernateConfigurationSection) ConfigurationManager.GetSection("nh");
            }
        }
    
        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return _properties;
            }
        }

        [StringValidator(InvalidCharacters=@" ~!@#$%^&*()[]{}/;'|\",MinLength=1,MaxLength=60)]
        public string HibernateFile
        {
            get { return (string)this["HibernateFile"];}
            set { this["HibernateFile"] = value;}
        }

        [StringValidator(InvalidCharacters=@" ~!@#$%^&*()[]{}/;'|\",MinLength=1,MaxLength=60)]
        public string MappingPath
        {
            get { return (string)this["MappingPath"];}
            set { this["MappingPath"] = value;}
        }

        [StringValidator(InvalidCharacters = @" ~!@#$%^&*()[]{}/;'|\", MinLength = 1, MaxLength = 60)]
        public NhTypeApplication NhTypeApplication
        {
            get { return (NhTypeApplication)this["NhTypeApplication"]; }
            set { this["NhTypeApplication"] = value; }
        }
    }
}